^ What's the point?
^ Requirements
^ Licenses
^ Installation
^ Usage
^ Functions

Download :: Top
File Operations Library

File Operations Library is a small Delphi component that uses Windows' IFileOperation interface for copying/moving/deleting etc. files and folders for use in Win32 and Win64 (Windows 10/11) software.

Features:
  • Copy, move, copy as, move as, delete files and folders, create folders
  • Copy, move, copy as, move as, delete files and folders, create folders in ZIP archive files (ZIP64 supported)
  • Place PIDLs or files and folders on the clipboard
  • Get PIDLs from the clipboard
  • Calculate folder sizes blazingly fast
  • Search for files and folders by a name pattern, size range or time range or search string (ANSI, UTF-8 and Unicode) with optional multi-threading
  • PIDL and filesystem based functions
  • As the IFileOperation interface is used windows automatically pops-up the Windows default progress window for actions taking longer time
  • Virtual folders are fully supported as far as IFileOperation supports the action



Requirements

Delphi Alexandria or above.


File Operations Library in shareware and commercial software?

The library can be avaluated freely, there are no limitations. If you like this component and use it in a freeware, shareware or commercial (or any other money making - advertising, in app. selling, etc.) product one of the licenses is needed.


Installation

Add the directory to the search path, and to Uses add: 'FileOperations'.


Functions

    function GetFileNameFromPIDL(Item: PItemIDList): String;
    function GetPIDLFromFileName(FileName: String): PItemIDList;
    function GetPIDLDisplayName(Item: PItemIDList): String;

    procedure CopyPIDLList(SourcePItemIDList: TArrayOfPItemIDList; var DestinationPItemIDList: TArrayOfPItemIDList);
    procedure FreePIDLList(var ArrayOfPItemIDList: TArrayOfPItemIDList);

    function FOCopyFiles(DestinationFolder: String; Files: TFOFileList; Handle: THandle): HRESULT; overload;
    function FOCopyFiles(DestinationFolder: PItemIDList; ItemIdList: TArrayOfPItemIDList; Handle: THandle): HRESULT; overload;

    function FOMoveFiles(DestinationFolder: String; Files: TFOFileList; Handle: THandle): HRESULT; overload;
    function FOMoveFiles(DestinationFolder: PItemIDList; ItemIdList: TArrayOfPItemIDList; Handle: THandle): HRESULT; overload;

    function FODeleteFiles(Files: TFOFileList; Permanently: Boolean; Handle: THandle): HRESULT; overload;
    function FODeleteFiles(ItemIdList: TArrayOfPItemIDList; Permanently: Boolean; Handle: THandle): HRESULT; overload;

    function FOCopyFile(DestinationFolder: String; FileName: String; NewFileName: String; Handle: THandle): HRESULT; overload;
    function FOCopyFile(DestinationFolder: PItemIDList; FileName: PItemIDList; NewFileName: String; Handle: THandle): HRESULT; overload;

    function FOMoveFile(DestinationFolder: String; FileName: String; NewFileName: String; Handle: THandle): HRESULT; overload;
    function FOMoveFile(DestinationFolder: PItemIDList; FileName: PItemIDList; NewFileName: String; Handle: THandle): HRESULT; overload;

    function FODeleteFile(FileItem: String; Permanently: Boolean; Handle: THandle): HRESULT; overload;
    function FODeleteFile(FileItem: PItemIDList; Permanently: Boolean; Handle: THandle): HRESULT; overload;

    function FOCreateFolder(DestinationFolder: PItemIDList; FolderName: String; Handle: THandle; var IsZIP: Boolean): HRESULT;

    function IsZIPFolder(PIDL: PItemIDList; var ZIPFileName: String): Boolean;
    function ZIPFolderPath(PIDL: PItemIDList): String;

    function FOCopyFilesToZIP(DestinationFolder: PItemIDList; ItemIdList: TArrayOfPItemIDList; Handle: THandle; ZipProgressEvent: TZipProgressEvent = nil; ZIPProgressCompleted: TZIPProgressCompleted = nil): HRESULT; overload;
    function FOMoveFilesToZIP(DestinationFolder: PItemIDList; ItemIdList: TArrayOfPItemIDList; Handle: THandle; ZipProgressEvent: TZipProgressEvent = nil; ZIPProgressCompleted: TZIPProgressCompleted = nil): HRESULT; overload;
    function FOCopyFileToZIPAs(DestinationFolder: PItemIDList; Item: PItemIDList; NewFileName: String; Handle: THandle; ZipProgressEvent: TZipProgressEvent = nil; ZIPProgressCompleted: TZIPProgressCompleted = nil): HRESULT; overload;
    function FOMoveFileToZIPAs(DestinationFolder: PItemIDList; Item: PItemIDList; NewFileName: String; Handle: THandle; ZipProgressEvent: TZipProgressEvent = nil; ZIPProgressCompleted: TZIPProgressCompleted = nil): HRESULT; overload;
    function FODeleteFilesInZIP(ItemIdList: TArrayOfPItemIDList; Handle: THandle; ZipProgressEvent: TZipProgressEvent = nil; ZIPProgressCompleted: TZIPProgressCompleted = nil): HRESULT; overload;
    function FODeleteFileInZIP(Item: PItemIDList; Handle: THandle; ZipProgressEvent: TZipProgressEvent = nil; ZIPProgressCompleted: TZIPProgressCompleted = nil): HRESULT; overload;

    function CalculateFolderSizeFileSystem(FolderName: String): UInt64;
    function CalculateFolderSizePIDL(PIDL: PItemIDList; Handle: HWND): UInt64;
    function CalculateFolderSizeFileSystemList(FileList: TFOFileList; Handle: HWND): UInt64;
    function CalculateFolderSizeItemIDList(ItemIdList: TArrayOfPItemIDList; Handle: HWND): UInt64;

    procedure CopyFileNamesToClipboard(FileNames: TFOFileList);
    procedure CopyPIDLsToClipboard(ItemIdList: TArrayOfPItemIDList);
    function GetPIDLsFromClipboard(var ItemIdList: TArrayOfPItemIDList): Boolean;


Usage

Uses
    Winapi.ShlObj,
    FileOperations;

var
    FilesListPIDL: TArrayOfPItemIDList;
begin
    //* Create the PIDL item array
    SetLength(FilesListPIDL, ItemCount);
    for i := 0 to ItemCount - 1 do begin
        FilesListPIDL[i] := ILClone(MyPIDL);
    end;
    //* Call a FO function here...
    //* Free the PIDL item array when finished
    FreePIDLList(FilesListPIDL);
end;
Note: It's not needed to use ILClone() but then the PIDLs used must stay alive until the FO function returns, and do not call FreePIDLList() just do a simple SetLength(FilesListPIDL, 0); call.

To use a file/folder name as a PIDL:
Uses
    Winapi.ShlObj,
    ActiveX,
    FileOperations;

var
    MyPIDL: PItemIDList;
    FilesListPIDL: TArrayOfPItemIDList;
begin
    MyPIDL := GetPIDLFromFileName('C:\Folder\MyFile.txt');
    //* Create the PIDL item array (only 1 item now)
    SetLength(FilesListPIDL, 1);
    FilesListPIDL[0] := ILClone(MyPIDL);
    //* Call a FO function here...
    //* Free the PIDL item array when finished
    FreePIDLList(FilesListPIDL);
    //* Free our PIDL
    ILFree(MyPIDL);
end;
Note: It's not needed to use ILClone() but then the PIDLs used must stay alive until the FO function returns, and do not call FreePIDLList() just do a simple SetLength(FilesListPIDL, 0); call.

To paste items from the clipboard (not ZIP destination case):
var
    ItemList: TArrayOfPItemIDList;
begin
    if GetPIDLsFromClipboard(ItemList) then begin
        FOCopyFiles(FolderPIDL, ItemList, Self.Handle);
        FreePIDLList(ItemList);
    end;
end;


[Top]